package info.mrmt.apps.PeculiarBrowser;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Display;
import android.view.WindowManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;

public class PeculiarBrowserActivity extends Activity {
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new BrowserLayout(this));
    }
}

interface IBrowserController {
	
	void setHomePage(int screenId);
}

class BrowserLayout extends LinearLayout implements IBrowserController {
	
	private static final int DEFAULT_WINDOW_NUM = 4;
	private static final String[] DEFAULT_URL = { //TODO
		"http://www.google.co.jp", "http://www.yahoo.co.jp",
		"http://www.sony.co.jp", "http://www.youtube.com"};
	
	private LinearLayout mUpperLayout = null;
	private LinearLayout mLowerLayout = null;
	
	private int mWidth;
	private int mHeight;
	
	private List<IBrowserElement> mBrowserElementList;

	public BrowserLayout(Context context) {
		super(context);
		setOrientation(LinearLayout.VERTICAL);
		
		WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		Display disp = wm.getDefaultDisplay();
		mWidth = disp.getWidth();
		mHeight = disp.getHeight();
		
		int browserElementWidth = Math.round(mWidth*0.5f);
		int browserElementHeight = Math.round(mHeight*0.5f);
		
		mBrowserElementList = new ArrayList<IBrowserElement>();
		for (int i = 0; i < DEFAULT_WINDOW_NUM; i++) {
			IBrowserElement be = new BrowserElement(context, i, browserElementWidth, browserElementHeight);
			be.setSize(browserElementWidth, browserElementHeight);
			be.loadUrl(DEFAULT_URL[i]);
			mBrowserElementList.add(be);
		}
		
		//initialize upper layout
		mUpperLayout = new LinearLayout(context);
		mUpperLayout.setOrientation(LinearLayout.HORIZONTAL);
		mUpperLayout.setLayoutParams(new android.widget.LinearLayout.LayoutParams(mWidth, Math.round(mHeight*0.5f)));
		mUpperLayout.addView((BrowserElement) mBrowserElementList.get(0));
		mUpperLayout.addView((BrowserElement) mBrowserElementList.get(1));
		addView(mUpperLayout);
		
		//initialize lower Layout
		mLowerLayout = new LinearLayout(context);
		mLowerLayout.setOrientation(LinearLayout.HORIZONTAL);
		mLowerLayout.setLayoutParams(new android.widget.LinearLayout.LayoutParams(mWidth, Math.round(mHeight*0.5f)));
		mLowerLayout.addView((BrowserElement) mBrowserElementList.get(2));
		mLowerLayout.addView((BrowserElement) mBrowserElementList.get(3));
		addView(mLowerLayout);
	}

	public void setHomePage(int screenId) {
		// TODO Auto-generated method stub
		
	}
	
}

